home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLSRC.PAK / MODEGAD.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  1.4 KB  |  59 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.5  $
  6. //
  7. // Defines TModeGadget.
  8. //
  9. // A mode gadget is a gadget that displays the mode of a key.
  10. // The key code is defined as VK_XXXX in Windows.
  11. //----------------------------------------------------------------------------
  12. #include <owl/pch.h>
  13. #if !defined(OWL_MODEGAD_H)
  14. # include <owl/modegad.h>
  15. #endif
  16.  
  17. OWL_DIAGINFO;
  18.  
  19. //
  20. // Initialize the text gadget with text key's text.
  21. //
  22. TModeGadget::TModeGadget(int vkKey, const char far* text, int id,
  23.   TBorderStyle border, TAlign align, TFont* font)
  24. :
  25.   TTextGadget(id, border, align, 10, text, font), VkKey(vkKey)
  26. {
  27.   SetShrinkWrap(true, true);
  28. }
  29.  
  30. //
  31. // Override from TGadget to update the state of the key.
  32. //
  33. bool
  34. TModeGadget::IdleAction(long count)
  35. {
  36.   TTextGadget::IdleAction(count);
  37.   int state = ::GetKeyState(VkKey);
  38.  
  39.   // Toggle keys
  40.   //
  41.   if (VkKey == VK_SCROLL || VkKey == VK_INSERT ||
  42.       VkKey == VK_NUMLOCK || VkKey == VK_CAPITAL) {
  43.     if (state & 1)
  44.       SetEnabled(true);
  45.     else
  46.       SetEnabled(false);
  47.   }
  48.   else {
  49.     // This is a regular key, highlite only when pressed
  50.     //
  51.     if (state & (1 << (sizeof(int) * 8 - 1)))
  52.       SetEnabled(true);
  53.     else
  54.       SetEnabled(false);
  55.   }
  56.   return false;
  57. }
  58.  
  59.